package com.sanjin.service.impl;

import com.sanjin.entity.SysLog;
import com.sanjin.exception.MyException;
import com.sanjin.repository.SysLogRepository;
import com.sanjin.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/9 21:51
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogRepository sysLogRepository;


    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public SysLog createSysLog(SysLog sysLog) {
        if (sysLog.getId() != null)
            throw new MyException("[创建日志] sysLog.id 必须为null");
        return sysLogRepository.save(sysLog);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public List<SysLog> getSysLogs() {
        return sysLogRepository.findAll();
    }
}
